<?php
/*
 * @Author: CYH
 * @Date: 2020-10-31 10:25:06
 * @LastEditTime: 2021-05-12 11:40:00
 * @LastEditors: Please set LastEditors
 * @Description: 退宿管理model类
 * @FilePath: \application\models\Register\Tune_in.php
 */
    //退宿管理model类
    class Tune_in extends CI_Model
    {
        //构造方法
        public function __construct()
        {

            parent::__construct();
            $this->load->database();
        }

        /**
         * @description: 调宿人员查询方法
         * @param {name,jobNumber}
         * @return {*}
         */        
        public function tune_in_select($name, $jobNumber)
        {
            if ($name == '' || $jobNumber == '') 
            {
                $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                $result = json_encode($return);
            } 
            else 
            {
                $query_dorm_livepeople = $this->db->get_where('dorm_livepeople' ,array('name' => $name ,'jobNumber' => $jobNumber));
                if($query_dorm_livepeople->num_rows()>0)
                {
                    $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $query_dorm_livepeople->row());
                    $result = json_encode($return_su);
                } 
                else 
                {
                        $return_fa = array('res' => '40001', 'msg' => '查询无数据' ,'data' => '');
                        $result = json_encode($return_fa);
                }
            }
            return $result;
        }

        /**
         * @description: 调换宿舍信息查询方法:取区域
         * @param {*}
         * @return {*}
         */        
        public function tune_in_area()
        {
            $select = array('area_number' ,'area_name' ,'area_location');
            $this->db->select($select);
            $query = $this->db->get('dorm_area');
            if($query)
            {
                $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $query->result());
                $result = json_encode($return_su);
            } 
            else 
            {
                $return_fa = array('res' => '40001', 'msg' => '查询无数据');
                $result = json_encode($return_fa);
            }
            return $result;
        }

        /**
         * @description: 调换宿舍信息查询方法:取宿舍楼
         * @param {area_number}
         * @return {*}
         */        
        public function tune_in_dorm($area_number)
        {
            if ($area_number == '') 
            {
                $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                $result = json_encode($return);
            } 
            else 
            {
                //取此区域的所有宿舍楼
                $select = array('floor_number' ,'floor_name' ,'floor_location');
                $this->db->select($select);
                $this->db->where('area_number' ,$area_number);
                $query = $this->db->get('dorm_sslmanage');
                if ($query->num_rows() > 0) 
                {
                    $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $query->row());
                    $result = json_encode($return_su);
                } 
                else 
                {
                    $return_fa = array('res' => '40001', 'msg' => '查询无数据');
                    $result = json_encode($return_fa);
                }
            }
            return $result;
        }

        /**
         * @description: 调换宿舍信息查询方法:取楼层
         * @param {area_number, floor_number}
         * @return {*}
         */        
        public function tune_in_floor($area_number, $floor_number)
        {
            if ($area_number == '' || $floor_number == '') 
            {
                $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                $result = json_encode($return);
            } 
            else 
            {
                $arr = [];
                if($area_number = '1585' && $floor_number = '1')
                {
                    $arr = [3,4,5,6];
                }
                elseif($area_number = '1585' && $floor_number = '2')
                {
                    $arr = [1];
                }
                elseif($area_number = '333' && $floor_number = '3')
                {
                    $arr = [1,2,3];
                }
                elseif($area_number = '178' && $floor_number = '4')
                {
                    $arr = [1];
                }
                if(count($arr)>0)
                {
                    $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $arr);
                    $result = json_encode($return_su);
            
                }
                else 
                {
                    $return_fa = array('res' => '40001', 'msg' => '查询无数据');
                    $result = json_encode($return_fa);
                }
            }
            return $result;
        }

        /**
         * @description: 调换宿舍信息查询方法:取宿舍
         * @param {area_number, floor_number, dorm_floor}
         * @return {*}
         */        
        public function tune_in_room($area_number ,$floor_number ,$dorm_floor)
        {
            if ($area_number == '' || $floor_number == '' || $dorm_floor == '') 
            {
                $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                $result = json_encode($return);
            } 
            else 
            {
                //取此楼层的所有房间
                $sj_dorm_roominfor = "area_number = '".$area_number."' AND floor_number = '".$floor_number."' AND dorm_floor = '".$dorm_floor."' AND remainNumber > 0";
                $sql_dorm_roominfor = "SELECT room_number FROM dorm_roominfor WHERE ".$sj_dorm_roominfor;
                $query = $this->db->query($sql_dorm_roominfor ,$sj_dorm_roominfor);
                if($query->num_rows()>0)
                {
                    $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $query->result());
                    $result = json_encode($return_su);
                } 
                else 
                {
                    $return_fa = array('res' => '40001', 'msg' => '查询无数据' ,'data' => '');
                    $result = json_encode($return_fa);
                }
            }
            return $result;
        }

        /**
         * @description: 调换宿舍信息查询方法:取床位
         * @param {area_number, floor_number, room_number}
         * @return {*}
         */        
        public function tune_in_bed($area_number ,$floor_number ,$room_number)
        {
            if ($area_number == '' || $floor_number == '' || $room_number == '') 
            {
                $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                $result = json_encode($return);
            } 
            else 
            {
                //取此宿舍的所有床位
                $where = array('area_number' => $area_number ,'floor_number' => $floor_number ,'room_number' => $room_number ,'check_inWhether' => 0);
                $this->db->select('bedNumber');
                $this->db->where($where);
                $query = $this->db->get('dorm_bed');
                if($query->num_rows()>0)
                {
                    $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $query->result());
                    $result = json_encode($return_su);
                } 
                else 
                {
                    $return_fa = array('res' => '40001', 'msg' => '查询无数据' ,'data' => '');
                    $result = json_encode($return_fa);
                }
            }
            return $result;
        }

        /**
         * @description: 调换宿舍信息查询方法：取柜子/判断床位
         * @param {area_name, floor_name, dorm_floor, room_number, bedNumber}
         * @return {*}
         */        
        public function tune_in_isbed($area_name, $floor_name, $dorm_floor, $room_number, $bedNumber)
        {
            if ($area_name == '' || $floor_name == '' || $dorm_floor == '' || $room_number == '' || $bedNumber == '') 
            {
                $return = array('res' => '40002', 'msg' => '请输入必填字段', 'data' => '');
                $result = json_encode($return);
            } 
            else 
            {
                $query = $this->db->get_where('dorm_sslmanage', array('area_name' => $area_name, 'floor_name' => $floor_name));
                $query1 = $this->db->get_where('dorm_livepeople', array('area_number' => $query->row()->area_number, 'floor_number' => $query->row(0)->floor_number, 'room_number' => $room_number, 'bedNumber' => $bedNumber));
                $query2 = $this->db->get_where('dorm_livepeople', array('area_number' => $query->row(0)->area_number, 'floor_number' => $query->row(0)->floor_number, 'room_number' => $room_number));
                if ($query1->num_rows() > 0) 
                {
                    $return_fa = array('res' => '40001', 'msg' => '所调换宿舍床位有人', 'data' => '');
                    $result = json_encode($return_fa);
                } 
                else 
                {
                    $return_su = array('res' => '40000', 'msg' => '柜子调换成功', 'data' => $bedNumber, 'wardrobe' => $query2->row()->wardrobe);
                    $result = json_encode($return_su);
                }
            }
            return $result;
        }

        /**
         * @description: 调换宿舍信息查询方法：判断柜子
         * @param {idNumber, area_name, floor_name, dorm_floor, room_number, wardrobe}
         * @return {*}
         */        
        public function tune_in_wardrobe($idNumber, $area_name, $floor_name, $dorm_floor, $room_number, $wardrobe)
        {
            if ($idNumber == '' || $area_name == '' || $floor_name == '' || $dorm_floor == '' || $room_number == '') 
            {
                $return = array('res' => '40002', 'msg' => '请输入必填字段', 'data' => '');
                $result = json_encode($return);
            } 
            else 
            {
                $query = $this->db->get_where('dorm_sslmanage', array('area_name' => $area_name, 'floor_name' => $floor_name));
                $query1 = $this->db->get_where('dorm_livepeople', array('area_number' => $query->row()->area_number, 'floor_number' => $query->row()->floor_number, 'room_number' => $room_number, 'wardrobe' => $wardrobe));
                if ($query1->num_rows() > 0) 
                {
                    $return_fa = array('res' => '40001', 'msg' => '所选柜子有人使用', 'data' => '');
                    $result = json_encode($return_fa);
                } 
                else 
                {
                    $return_su = array('res' => '40000', 'msg' => '所选柜子无人使用，可以使用', 'data' => $wardrobe);
                    $result = json_encode($return_su);
                }
            }
            return $result;   
        }

         /*调宿进行步骤
        1.人员信息表更新
        2.床位表更新
        3.记录表数据插入
        4.房间表的宿舍实际人数和宿舍剩余可住人数更新
        5.水电人天表更新
        */

        /**
         * @description: 调宿方法
         * @param {CoordinatingDate, name, jobNumber, sex, department, check_inAddress, area_number, floor_number, room_number, bedNumber, room_hotwater, room_coldwater, room_electric, remarks}
         * @return {*}
         */        
        // public function tune_in($CoordinatingDate, $name, $jobNumber, $idNumber, $sex, $department, $check_inAddress, $area_number, $floor_number, $dorm_floor, $room_number, $bedNumber, $room_hotwater, $room_coldwater, $room_electric, $remarks)
        public function tune_in($CoordinatingDate, $name, $jobNumber, $idNumber, $sex, $department1, $department2, $department3, $check_inAddress, $area_number, $floor_number, $dorm_floor, $room_number, $bedNumber, $remarks)
        {
            // if($CoordinatingDate == '' || $name == '' || $jobNumber == '' || $sex == '' || $department1 == '' || $department2 == '' || $department3 == '' || $check_inAddress == '' || $area_number == '' || $floor_number == '' || $room_number == '' || $bedNumber == '' || $room_hotwater == '' || $room_coldwater == '' || $room_electric == ''){
            if($CoordinatingDate == '' || $name == '' || $sex == '' || $check_inAddress == '' || $area_number == '' || $floor_number == '' || $room_number == '' || $bedNumber == ''){
                $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                $result = json_encode($return);

            } 
            else 
            {
                // //取水电表数据
                // $query_dorm_manday_calc_se = $this->db->get_where('dorm_manday_calc' ,array('name' => $name ,'jobNumber' => $jobNumber));

                // //调宿日期正确性校验
                // /*1.若数据大于一条则取调宿日期最近的日期进行判断，若调宿日期-上一次调宿日期<0则报错
                //   2.若只有一条数据则取房间入住日期进行判断，若调宿日期-房间入住日期<0报错
                //   3.若一条数据都没有，则取人员信息的入住日期进行判断，若调宿日期-入住日期<0报错
                // */

                // //若数据大于一条则取房间入住日期最近的日期进行判断，若调宿日期-房间入住日期<0则报错
                // if($query_dorm_manday_calc_se->num_rows()>1)
                // {
                //     $sj_dorm_manday_calc_se = "name LIKE '%".$name."%' AND jobNumber LIKE '%".$jobNumber."%' ORDER BY room_livedate DESC LIMIT 1";
                //     $sql_dorm_manday_calc_se = "SELECT * FROM dorm_manday_calc WHERE " .$sj_dorm_manday_calc_se;
                //     $query_dorm_manday_calc_se1 = $this->db->query($sql_dorm_manday_calc_se ,$sj_dorm_manday_calc_se);
                //     // $start_Coordinating_date = new DateTime($query_dorm_manday_calc_se1->row()->CoordinatingDate);
                //     // $end_Coordinating_date = new DateTime($CoordinatingDate);
                //     $start_Coordinating_date = strtotime($query_dorm_manday_calc_se1->row()->CoordinatingDate);
                //     $end_Coordinating_date = strtotime($CoordinatingDate);
                // //若只有一条数据则取房间入住日期进行判断，若调宿日期-房间入住日期<0报错
                // }
                // elseif($query_dorm_manday_calc_se->num_rows()==1)
                // {
                //     $sj_dorm_manday_calc_se = "name LIKE '%".$name."%' AND jobNumber LIKE '%".$jobNumber."%'";
                //     $sql_dorm_manday_calc_se = "SELECT * FROM dorm_manday_calc WHERE " .$sj_dorm_manday_calc_se;
                //     $query_dorm_manday_calc_se1 = $this->db->query($sql_dorm_manday_calc_se ,$sj_dorm_manday_calc_se);
                //     // $start_Coordinating_date = new DateTime($query_dorm_manday_calc_se1->row()->room_livedate);
                //     // $end_Coordinating_date = new DateTime($CoordinatingDate);
                //     $start_Coordinating_date = strtotime($query_dorm_manday_calc_se1->row()->room_livedate);
                //     $end_Coordinating_date = strtotime($CoordinatingDate);
                
                // //若一条数据都没有，则取人员信息的入住日期进行判断，若调宿日期-入住日期<0报错
                // } 
                // else 
                // {
                //     $sj_dorm_manday_calc_se = "name LIKE '%".$name."%' AND jobNumber LIKE '%".$jobNumber."%'";
                //     $sql_dorm_manday_calc_se = "SELECT * FROM dorm_livepeople WHERE " .$sj_dorm_manday_calc_se;
                //     $query_dorm_manday_calc_se1 = $this->db->query($sql_dorm_manday_calc_se ,$sj_dorm_manday_calc_se);
                //     // $start_Coordinating_date = new DateTime($query_dorm_manday_calc_se1->row()->liveDate);
                //     // $end_Coordinating_date = new DateTime($CoordinatingDate);
                //     $start_Coordinating_date = strtotime($query_dorm_manday_calc_se1->row()->liveDate);
                //     $end_Coordinating_date = strtotime($CoordinatingDate);
                // }

                //日期差值计算                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                // $live_days = $start_Coordinating_date->diff($end_Coordinating_date)->days;
                // $live_days = ($end_Coordinating_date - $start_Coordinating_date) / 86400;

                //调宿日期有误进行报错
                // if($live_days<=0)
                // {
                //     $return = array('res' => '40001', 'msg' => '请检查调宿日期' ,'data' => '');
                //     $result = json_encode($return);
                // } 
                // else 
                // {

                /*人员信息表更新*/

                    //取要调宿的房间的楼层号
                    $dorm_floor = substr($room_number ,0 ,1);

                    //入住位置拼接
                    $check_in_address = $area_number.'*'.$dorm_floor.'*'.$room_number.'*'.$bedNumber;

                    //取当前日期
                    $date_now = date("Y-m-d");
                    
                    //人员的房间信息取出
                    $query_livepeople_old = $this->db->get_where('dorm_livepeople', array('name' => $name, 'jobNumber' => $jobNumber));

                    //更新入住人员信息表
                    $data_livepeople = array(
                        'area_number' => $area_number,                     //区域编号
                        'floor_number' => $floor_number,                   //宿舍楼编号
                        'room_number' => $room_number,                     //宿舍房间号
                        'dorm_floor' => $dorm_floor,                       //宿舍楼层号
                        'check_inAddress' => $check_in_address,            //入住位置
                        'bedNumber' => $bedNumber,                         //床位号
                        'tune_inCheck' => 'X',                             //是否已调宿
                        'tune_inDate' => $CoordinatingDate                 //调宿日期
                    );
                    $where_livepeople_new_update = array('name' => $name ,'jobNumber' => $jobNumber);
                    $this->db->where($where_livepeople_new_update);
                    $this->db->update('dorm_livepeople' ,$data_livepeople);
                    $result_livepeople = $this->db->affected_rows();

                /*床位表更新*/

                    //取床位表人员信息
                    $query_bed_data = $this->db->get('dorm_bed');

                    //将调宿的人员先从这个床位退宿
                    $data_bed_old = array(
                        'name' => '',           //姓名
                        'sex' => '',            //性别
                        'idNumber' => '',       //身份证号
                        'jobNumber' => '',      //工号
                        'department1' => '',    //一级部门
                        'department2' => '',    //二级部门
                        'department3' => '',    //三级部门
                        'phone' => '',          //联系方式
                        'check_inWhether' => 0, //是否住人
                        'remarks' => ''         //备注
                    );

                    $where_bed_old = array('name' => $name ,'jobNumber' => $jobNumber);
                    $this->db->where($where_bed_old);
                    $this->db->update('dorm_bed' ,$data_bed_old);
                    $result_bed_old = $this->db->affected_rows();

                    //再将这个人员入住到新的床位
                    $where_bed = array('area_number' => $area_number ,'floor_number' => $floor_number ,'room_number' => $room_number ,'bedNumber' => $bedNumber );
                    $data_bed_new = array(
                        'name' => $name,                                    //人员姓名
                        'sex' => $sex,                                      //性别
                        'idNumber' => $query_bed_data->row()->idNumber,     //身份证号
                        'jobNumber' => $jobNumber,                          //工号
                        'department1' => $department1,                      //一级部门
                        'department2' => $department2,                      //二级部门
                        'department3' => $department3,                      //三级部门
                        'phone' => $query_bed_data->row()->phone,           //联系方式
                        'check_inWhether' => 1,                             //床位是否住人
                    );
                    $this->db->where($where_bed);
                    $this->db->update('dorm_bed' ,$data_bed_new);
                    $result_bed_new = $this->db->affected_rows();

                /*记录表数据插入*/

                    //取此人员的所有信息
                    $query_livepeople_data = $this->db->get_where('dorm_livepeople' ,array('name' => $name ,'jobNumber' => $jobNumber));

                    //数据插入记录表
                    $data_tune_in = array(
                        'area_number' => $area_number,                                              //区域编号
                        'floor_number' => $floor_number,                                            //宿舍楼编号
                        'dorm_floor' => $dorm_floor,                                                //宿舍楼层号
                        'room_number' => $room_number,                                              //宿舍房间号
                        'idNumber' => $query_livepeople_data->row()->idNumber,                      //身份证号
                        'jobNumber' => $jobNumber,                                                  //工号
                        'name' => $name,                                                            //人员姓名
                        'department1' => $department1,                                              //一级部门
                        'department2' => $department2,                                              //二级部门
                        'department3' => $department3,                                              //三级部门
                        'job' => $query_livepeople_data->row()->job,                                //职位
                        'sex' => $sex,                                                              //性别
                        'phone' => $query_livepeople_data->row()->phone,                            //联系方式
                        'location' => $query_livepeople_data->row()->location,                      //籍贯
                        'address' => $query_livepeople_data->row()->address,                        //户籍地址
                        'type' => 2,                                                                //0:退宿 1:入住 2:调宿 类别
                        'apply_date' => $date_now,                                                  //申请日期
                        'bedNumber' => $bedNumber,                                                  //床位号
                        'wardrobe' => $query_livepeople_data->row()->wardrobe,                      //柜子号
                        'reason' => $remarks,                                                       //申请原因
                        // 'liveDate' => $query_livepeople_data->row()->liveDate,                   //入住日期
                        'liveDate' => $CoordinatingDate,                                            //入住日期(新房间入住日期)
                        'emergencyContact' => $query_livepeople_data->row()->emergencyContact,      //紧急联系人
                        'relationShip' => $query_livepeople_data->row()->relationShip,              //与紧急联系人关系
                        'emergencyPhone' => $query_livepeople_data->row()->emergencyPhone,          //紧急联系人联系方式
                        'changeNumber' => $room_number,                                             //变更房号
                        'changeBed' => $bedNumber,                                                  //变更床位
                        'changeDate' => $CoordinatingDate,                                          //变更日期
                        'remarks' => $remarks,                                                      //备注
                        'applyName' => $name                                                        //申请人
                    );
                    $this->db->insert('dorm_stay_retreat_tune' ,$data_tune_in);
                    $result_tune = $this->db->affected_rows();

                /*房间表的宿舍实际人数和宿舍剩余可住人数更新*/

                    //宿舍房间表数据取出
                    $query_old_roominfor = $this->db->get_where('dorm_roominfor', array('area_number' => $query_livepeople_old->row()->area_number ,'floor_number' => $query_livepeople_old->row()->floor_number ,'room_number' => $query_livepeople_old->row()->room_number));

                    //原宿舍的宿舍实际人数-1
                    $SS_peoplenumber_old_Weniger = $query_old_roominfor->row()->peopleNumber - 1; 

                    //原宿舍的宿舍剩余可住+1
                    $SS_remain_people_old_add = $query_old_roominfor->row()->remainNumber + 1;      

                    //宿舍房间表原宿舍的宿舍实际人数和宿舍剩余可住人数更新
                    $data_old_roominfor = array(
                        'peopleNumber' => $SS_peoplenumber_old_Weniger, //当前宿舍的实际人数
                        'remainNumber' => $SS_remain_people_old_add     //当前宿舍的剩余可住人数
                    );
                    $where_livepeople_old = array('area_number' => $query_livepeople_old->row()->area_number ,'floor_number' => $query_livepeople_old->row()->floor_number ,'room_number' => $query_livepeople_old->row()->room_number);
                    $this->db->where($where_livepeople_old);
                    $this->db->update('dorm_roominfor' ,$data_old_roominfor);
                    $result_roominfor_old = $this->db->affected_rows();
                    
                    //取新宿舍的宿舍实际人数,剩余可住人数
                    $query_new_roominfor = $this->db->get_where('dorm_roominfor', array('area_number' => $area_number, 'floor_number' => $floor_number, 'room_number' => $room_number));
                    
                    //新宿舍的宿舍实际人数+1
                    $SS_peoplenumber_new_add = $query_new_roominfor->row()->peopleNumber + 1;   

                    //新宿舍的宿舍剩余可住人数-1
                    $SS_remain_people_new_Weniger = $query_new_roominfor->row()->remainNumber -1;  

                    //宿舍房间表换后宿舍的宿舍实际人数和宿舍剩余可住人数更新
                    $where_livepeople_new = array(
                        'area_number' => $area_number,       //区域编号
                        'floor_number' => $floor_number,     //宿舍楼编号
                        'room_number' => $room_number
                    );

                    $data_new_roominfor = array(
                        'peopleNumber' => $SS_peoplenumber_new_add,       //新宿舍的实际人数
                        'remainNumber' => $SS_remain_people_new_Weniger   //新宿舍的剩余可住人数
                    );
                    $this->db->where($where_livepeople_new);
                    $this->db->update('dorm_roominfor' ,$data_new_roominfor);
                    $result_roominfor_new = $this->db->affected_rows();

                    //取人员楼层号
                    $dormfloor = $this->db->get_where('dorm_livepeople', array('jobNumber' => $jobNumber));

                /*水电人天表更新*/

                    //若存在免扣水电的情况需要减去免扣水电的天数
                    //取免扣水电表中的最新的人员信息
                    // $sql_leave_off = "SELECT * FROM dorm_leave_off WHERE name LIKE '%".$name."%' AND jobNumber LIKE '%".$jobNumber."%' ORDER BY apply_beginDate DESC LIMIT 1";
                    // $query_leave_off = $this->db->query($sql_leave_off);

                    // //若此人存在水电免扣的信息则进行下面的逻辑
                    // if($query_leave_off->num_rows()>0)
                    // {
                        
                    //     //申请日期开始日期的年份
                    //     $year_beginDate = substr($query_leave_off->row()->apply_beginDate, 0, 4);

                    //     //申请日期开始日期的月份
                    //     $month_beginDate = substr($query_leave_off->row()->apply_beginDate, 5, 2);

                    //     //申请日期结束日期的年份
                    //     $year_endDate = substr($query_leave_off->row()->apply_endDate, 0, 4);

                    //     //申请日期结束日期的月份
                    //     $month_endDate = substr($query_leave_off->row()->apply_endDate, 5, 2);

                    // }


                    /*计算所住房间的居住天数
                    1.若有多条取最近的一条房间入住日期的数据的房间入住日期与输入的调宿日期比较，若同年同月则入住天数 = 调宿日期 - 房间入住日期 ，若不同则入住天数 = 调宿日期 - 当年当月的第一天,若存在水电免扣则减去水电免扣的申请天数
                    2.若只有一条数据取这条数据的房间入住日期与所输的调宿日期比较，若同年同月则入住天数 = 调宿日期 - 房间入住日期 ，若不同则调宿日期 - 当年当月的第一天,若存在水电免扣则减去水电免扣的申请天数
                    3.若水电表一条数据都没有将人员的入住日期与所输的调宿日期比较，若同年同月则入住天数 = 调宿日期 - 入住日期 ，若不同则入住天数 = 调宿日期 - 当年当月的第一天，若存在水电免扣则减去水电免扣的申请天数
                        (1)先计算入住天数 
                        (2)减去免扣水电天数 
                        (3)插入数据到水电表更新入住天数 
                        (4)再插一条数据到水电表中更新调宿日期*/

                    /*水电免扣逻辑
                    1.如果申请日期开始日期年份月份等于当年当月,并且申请日期结束日期年份月份也等于当年当月 则入住天数 = 原入住天数 - 申请天数
                    2.如果申请日期开始日期年份月份等于当年当月,申请日期结束日期年份月份也等于当年不等于当月 则入住天数 = 原入住天数 - (当月最后一天-申请日期开始日期)
                    */

                    //若有多条取最近的一条房间入住日期的数据的房间入住日期与输入的调宿日期比较，若同年同月则入住天数 = 调宿日期 - 房间入住日期 ，若不同则入住天数 = 调宿日期 - 当年当月的第一天,若存在水电免扣则减去水电免扣的申请天数
                    // if($query_dorm_manday_calc_se->num_rows()>1)
                    // {

                    //     //取最近一条房间入住日期的年份
                    //     $year = substr($query_dorm_manday_calc_se1->row()->room_livedate ,0 ,4);

                    //     //取最近一条房间入住日期的月份
                    //     $month = substr($query_dorm_manday_calc_se1->row()->room_livedate ,5 ,2);

                    //     //若同年同月则入住天数 = 调宿日期 - 房间入住日期
                    //     if($year == date("Y") && $month == date("m"))
                    //     {
                    //         // $start_Coordinating_date1 = new DateTime($query_dorm_manday_calc_se1->row()->room_livedate);
                    //         // $end_room_livedate = new DateTime($CoordinatingDate);
                    //         // $live_days = $start_Coordinating_date1->diff($end_room_livedate)->days;
                    //         $start_Coordinating_date1 = strtotime($query_dorm_manday_calc_se1->row()->room_livedate);
                    //         $end_room_livedate = strtotime($CoordinatingDate);
                    //         $live_days = ($end_room_livedate - $start_Coordinating_date1) / 86400;
                        
                    //     //若不同则入住天数 = 调宿日期 - 调宿年调宿日期月的第一天
                    //     } 
                    //     else 
                    //     {
                    //         $CoordinatingDate_year = substr($CoordinatingDate, 0, 4);
                    //         $CoordinatingDate_month = substr($CoordinatingDate, 5, 2);
                    //         // $start_Coordinating_date1 = new DateTime(date("$CoordinatingDate_year-$CoordinatingDate_month-01"));
                    //         // $end_month = new DateTime($CoordinatingDate);
                    //         // $live_days = $start_Coordinating_date1->diff($end_month)->days;
                    //         $start_Coordinating_date1 = strtotime(date("$CoordinatingDate_year-$CoordinatingDate_month-01"));
                    //         $end_month = strtotime($CoordinatingDate);
                    //         $live_days = ($end_month - $start_Coordinating_date1) / 86400;
                    //     }

                    //     //若存在水电免扣则减去水电免扣的申请天数
                    //     if($query_leave_off->num_rows()>0)
                    //     {

                    //         //如果申请日期开始日期年份月份等于当年当月,并且申请日期结束日期年份月份也等于当年当月 则入住天数 = 原入住天数 - 申请天数
                    //         if( ( $year_beginDate == date("Y") && $month_beginDate = date("m") ) && ( $year_endDate == date("Y") && $month_endDate == date("m") ) )
                    //         {
                    //             $live_days = $live_days - $query_leave_off->row()->apply_days;

                    //         //如果申请日期开始日期年份月份等于当年当月,申请日期结束日期年份月份也等于当年不等于当月 则入住天数 = 原入住天数 - (当月最后一天-申请日期开始日期)
                    //         // }elseif( ( $year_beginDate == date("Y") && $month_beginDate = date("m") ) && ( $year_endDate == date("Y") && $month_endDate != date("m") ) ){
                    //         }
                    //         else
                    //         {
                    //             // $start_apply_beginDate = new DateTime($query_leave_off->row()->apply_beginDate);//当月最后一天
                    //             // $end_month_last = new DateTime(date("Y-m-t"));
                    //             // $live_days = $live_days - $start_apply_beginDate->diff($end_month_last)->days;
                    //             $start_apply_beginDate = strtotime($query_leave_off->row()->apply_beginDate);//当月最后一天
                    //             $end_month_last = strtotime(date("Y-m-t"));
                    //             $live_days -= (($end_month_last - $start_apply_beginDate) / 86400);
                    //         }
                    //     }

                    //     //将入住天数进行更新
                    //     $sql_dorm_manday_calc_up = "UPDATE dorm_manday_calc SET liveDays = '".$live_days."' WHERE " .$sj_dorm_manday_calc_se ;
                    //     $this->db->query($sql_dorm_manday_calc_up ,$sj_dorm_manday_calc_se);
                    //     $result_manday_calc_up = $this->db->affected_rows();

                    //     //再插入一条数据
                    //     $data_manday_calc = array(
                    //         'area_number' => $area_number,                                          //区域编号
                    //         'floor_number' => $floor_number,                                        //宿舍楼编号
                    //         'room_number' => $room_number,                                          //宿舍房间号
                    //         'name' => $name,                                                        //姓名
                    //         'jobNumber' => $jobNumber,                                              //工号
                    //         'dorm_livedate' => $query_livepeople_old->row()->liveDate,              //宿舍入住日期
                    //         'room_livedate' => $CoordinatingDate,                                   //房间入住日期
                    //         'CoordinatingDate' => ''                                                //调宿日期
                    //     );
                    //     $this->db->insert('dorm_manday_calc' ,$data_manday_calc);
                    //     $query_manday_calc_up = $this->db->affected_rows();

                    // //若只有一条数据取这条数据的房间入住日期与所输的调宿日期与较，若同年同月则入住天数 = 调宿日期 - 房间入住日期 ，若不同则调宿日期 - 当年当月的第一天,若存在水电免扣则减去水电免扣的申请天数
                    // }
                    // elseif($query_dorm_manday_calc_se->num_rows()==1)
                    // {

                    //     //取人员房间入住日期的年份
                    //     $year = substr($query_dorm_manday_calc_se1->row()->room_livedate ,0 ,4);

                    //     //取人员房间入住日期的月份
                    //     $month = substr($query_dorm_manday_calc_se1->row()->room_livedate ,5 ,2);

                    //     //若同年同月则入住天数 = 调宿日期 - 房间入住日期
                    //     if($year == date("Y") && $month == date("m"))
                    //     {
                    //         // $start_Coordinating_date1 = new DateTime($query_dorm_manday_calc_se1->row()->room_livedate);
                    //         // $end_room_livedate = new DateTime($CoordinatingDate);
                    //         // $live_days = $start_Coordinating_date1->diff($end_room_livedate)->days;
                    //         $start_Coordinating_date1 = strtotime($query_dorm_manday_calc_se1->row()->room_livedate);
                    //         $end_room_livedate = strtotime($CoordinatingDate);
                    //         $live_days = ($end_room_livedate - $start_Coordinating_date1) / 86400;
                        
                    //     //若不同则入住天数 = 调宿日期 - 调宿年调宿日期月的第一天
                    //     } 
                    //     else 
                    //     {
                    //         $CoordinatingDate_year = substr($CoordinatingDate, 0, 4);
                    //         $CoordinatingDate_month = substr($CoordinatingDate, 5, 2);
                    //         // $start_Coordinating_date1 = new DateTime(date("$CoordinatingDate_year-$CoordinatingDate_month-01"));
                    //         // $end_month = new DateTime($query_dorm_manday_calc_se1->row()->Coordinating);
                    //         // $live_days = $start_Coordinating_date1->diff($end_month)->days;
                    //         $start_Coordinating_date1 = strtotime(date("$CoordinatingDate_year-$CoordinatingDate_month-01"));
                    //         $end_month = strtotime($query_dorm_manday_calc_se1->row()->Coordinating);
                    //         $live_days = ($end_month - $start_Coordinating_date1) / 86400;
                    //     }

                        
                    //     //若存在水电免扣则减去水电免扣的申请天数
                    //     if($query_leave_off->num_rows()>0)
                    //     {

                    //         //如果申请日期开始日期年份月份等于当年当月,并且申请日期结束日期年份月份也等于当年当月 则入住天数 = 原入住天数 - 申请天数
                    //         if( ( $year_beginDate == date("Y") && $month_beginDate = date("m") ) && ( $year_endDate == date("Y") && $month_endDate == date("m") ) )
                    //         {
                    //             $live_days = $live_days - $query_leave_off->row()->apply_days;
                    //         //如果申请日期开始日期年份月份等于当年当月,申请日期结束日期年份月份也等于当年不等于当月 则入住天数 = 原入住天数 - (当月最后一天-申请日期开始日期)
                    //         // }elseif( ( $year_beginDate == date("Y") && $month_beginDate = date("m") ) && ( $year_endDate == date("Y") && $month_endDate != date("m") ) ){
                    //         }
                    //         else
                    //         {
                    //             // $start_apply_beginDate = new DateTime($query_leave_off->row()->apply_beginDate);//当月最后一天
                    //             // $end_month_last = new DateTime(date("Y-m-t"));
                    //             // $live_days = $live_days - $start_apply_beginDate->diff($end_month_last)->days;
                    //             $start_apply_beginDate = strtotime($query_leave_off->row()->apply_beginDate);//当月最后一天
                    //             $end_month_last = strtotime(date("Y-m-t"));
                    //             $live_days -= (($end_month_last - $start_apply_beginDate) / 86400);
                    //         }
                    //     }

                    //     //先将这条数据的的入住天数更新
                    //     $manday_calc_up = array(
                    //         'liveDays' => $live_days   //入住天数
                    //     );
                    //     $this->db->where($where_livepeople_new_update);
                    //     $this->db->update('dorm_manday_calc' ,$manday_calc_up);
                    //     $query_manday_calc_up = $this->db->affected_rows();

                    //     //再插入一条数据
                    //     //取这个人员在水电表中的房间入住日期
                    //     $query_room_livedate= $this->db->get_where('dorm_manday_calc' ,array('name' => $name, 'jobNumber' => $jobNumber));

                    //     //将数据插入水电表
                    //     $data_manday_calc = array(
                    //         'area_number' => $area_number,                                          //区域编号
                    //         'floor_number' => $floor_number,                                        //宿舍楼编号
                    //         'room_number' => $room_number,                                          //宿舍房间号
                    //         'name' => $name,                                                        //姓名
                    //         'jobNumber' => $jobNumber,                                              //工号
                    //         'dorm_livedate' => $query_livepeople_old->row()->liveDate,              //宿舍入住日期
                    //         'room_livedate' => $query_Coordinating_date->row()->CoordinatingDate,   //房间入住日期
                    //         'CoordinatingDate' => $CoordinatingDate                                 //调宿日期
                    //     );
                    //     $this->db->insert('dorm_manday_calc' ,$data_manday_calc);
                    //     $query_manday_calc = $this->db->affected_rows();
                    
                    // //若水电表一条数据都没有将人员的入住日期与调宿日期比较，若同年同月则入住天数 = 调宿日期 - 入住日期 ，若不同则入住天数 = 调宿日期 - 当年当月的第一天，若存在水电免扣则减去水电免扣的申请天数
                    // } 
                    // else 
                    // {

                    //     //取人员入住日期的年份
                    //     $year = substr($query_dorm_manday_calc_se1->row()->liveDate ,0 ,4);

                    //     //取人员入住日期的月份
                    //     $month = substr($query_dorm_manday_calc_se1->row()->liveDate ,5 ,2);

                    //     //若同年同月则入住天数 = 调宿日期 - 入住日期
                    //     if($year == date("Y") && $month == date("m"))
                    //     {
                    //         // $start_Coordinating_date1 = new DateTime($query_dorm_manday_calc_se1->row()->liveDate);
                    //         // $end_room_livedate = new DateTime($CoordinatingDate);
                    //         // $live_days = $start_Coordinating_date1->diff($end_room_livedate)->days;
                    //         $start_Coordinating_date1 = strtotime($query_dorm_manday_calc_se1->row()->liveDate);
                    //         $end_room_livedate = strtotime($CoordinatingDate);
                    //         $live_days = ($end_room_livedate - $start_Coordinating_date1) / 86400;
                        
                    //     //若不同则入住天数 = 调宿日期 - 调宿年调宿日期月的第一天
                    //     } 
                    //     else 
                    //     {
                    //         $CoordinatingDate_year = substr($CoordinatingDate, 0, 4);
                    //         $CoordinatingDate_month = substr($CoordinatingDate, 5, 2);
                    //         // $start_Coordinating_date1 = new DateTime($CoordinatingDate);
                    //         // $end_month = new DateTime(date("$CoordinatingDate_year-$CoordinatingDate_month-01"));
                    //         // $live_days = $start_Coordinating_date1->diff($end_month)->days;
                    //         $start_Coordinating_date1 = strtotime($CoordinatingDate);
                    //         $end_month = strtotime(date("$CoordinatingDate_year-$CoordinatingDate_month-01"));
                    //         $live_days = ($end_month - $start_Coordinating_date1) / 86400;
                    //     }

                    //     //免扣水电天数
                    //     if($query_leave_off->num_rows()>0)
                    //     {

                    //         //入住天数计算
                    //         //如果申请日期开始日期年份月份等于当年当月,并且申请日期结束日期年份月份也等于当年当月 则入住天数 = 原入住天数 - 申请天数
                    //         if( ( $year_beginDate == date("Y") && $month_beginDate = date("m") ) && ( $year_endDate == date("Y") && $month_endDate == date("m") ) )
                    //         {
                    //             $live_days = $live_days - $query_leave_off->row()->apply_days;

                    //         //如果申请日期开始日期年份月份等于当年当月,申请日期结束日期年份月份也等于当年不等于当月 则入住天数 = 原入住天数 - (当月最后一天-申请日期开始日期)
                    //         // }elseif( ( $year_beginDate == date("Y") && $month_beginDate = date("m") ) && ( $year_endDate == date("Y") && $month_endDate != date("m") ) ){
                    //         }
                    //         else
                    //         {
                    //             // $start_apply_beginDate = new DateTime($query_leave_off->row()->apply_beginDate);//当月最后一天
                    //             // $end_month_last = new DateTime(date("Y-m-t"));
                    //             // $live_days = $live_days - $start_apply_beginDate->diff($end_month_last)->days;
                    //             $start_apply_beginDate = strtotime($query_leave_off->row()->apply_beginDate);//当月最后一天
                    //             $end_month_last = strtotime(date("Y-m-t"));
                    //             $live_days -= (($end_month_last - $start_apply_beginDate) / 86400);
                    //         }
                    //     }
                        
                    //     //数据插入水电表
                    //     $data_Coordinating_date_new = array(
                    //         'area_number' => $query_livepeople_old->row()->area_number,        //区域编号
                    //         'floor_number' => $query_livepeople_old->row()->floor_number,      //宿舍楼编号
                    //         'room_number' => $query_livepeople_old->row()->room_number,        //宿舍房间号
                    //         'name' => $name,                                                   //人员姓名
                    //         'jobNumber' => $jobNumber,                                         //工号
                    //         'dorm_livedate' => $query_livepeople_old->row()->liveDate,         //宿舍入住日期
                    //         'room_livedate' => $query_livepeople_old->row()->liveDate,         //房间入住日期
                    //         'liveDays' => $live_days                                           //入住天数
                    //         );
                    //         $this->db->insert('dorm_manday_calc' ,$data_Coordinating_date_new);

                    //         $data_Coordinating_date = array(
                    //             'CoordinatingDate' => $CoordinatingDate
                    //         );

                    //     //再插入一条数据
                    //     //先取最后一条数据的调宿日期
                    //     $sql_dorm_manday_calc_in = "SELECT CoordinatingDate FROM dorm_manday_calc WHERE name LIKE '%".$name."%' AND jobNumber LIKE '%".$jobNumber."%' ORDER BY CoordinatingDate DESC LIMIT 1";
                    //     $query_Coordinating_date = $this->db->query($sql_dorm_manday_calc_in);
                    //     $data_manday_calc = array(
                    //         'area_number' => $area_number,                                          //区域编号
                    //         'floor_number' => $floor_number,                                        //宿舍楼编号
                    //         'room_number' => $room_number,                                          //宿舍房间号
                    //         'name' => $name,                                                        //姓名
                    //         'jobNumber' => $jobNumber,                                              //工号
                    //         'dorm_livedate' => $query_livepeople_old->row()->liveDate,              //宿舍入住日期
                    //         'room_livedate' => $CoordinatingDate,                                   //房间入住日期
                    //         'CoordinatingDate' => $CoordinatingDate                                 //调宿日期
                    //     );
                    //     $this->db->insert('dorm_manday_calc' ,$data_manday_calc);
                    //     $query_manday_calc_up = $this->db->affected_rows();
                    // }

                /*退宿人员水电费计算*/

                    // $roomMeterArray = array(
                    //     'jobNumber' => $jobNumber,                                 //工号
                    //     'date' => strtotime(date("Y-m-d")),                        //当前时间时间戳
                    //     'date' => date("Y-m-d"),                                   //调宿时间  
                    //     'area_number' => explode('*', $check_inAddress)[0],        //区域编号
                    //     'floor_number' => explode('*', $check_inAddress)[1],       //宿舍楼编号
                    //     'dorm_floor' => $dormfloor->row()->dorm_floor,             //宿舍楼层号
                    //     'room_number' => explode('*', $check_inAddress)[2],        //宿舍房间号
                    //     'room_hotwater' => $room_hotwater,                         //房间热水表
                    //     'room_coldwater' => $room_coldwater,                       //房间冷水表
                    //     'room_electric' => $room_electric,                         //房间电表
                    //     'type' => 2                                                //房间电表
                    // );                  
                    // print_r($result_livepeople);
                    // print_r($result_bed_old);
                    // print_r($result_bed_new);
                    // print_r($result_tune);
                    // print_r($result_roominfor_old);
                    // print_r($result_roominfor_new);
                    // return;

                    //计算人员入住天数
                    //取人员的入住日期，若入住日期与调宿日期为同月则用调宿日期-入住日期若不同月则调宿日期-本月一号
                    $data_people = $this->db->get_where('dorm_livepeople', array('idNumber' => $idNumber, 'jobNumber' => $jobNumber));
                    $query_people = $data_people->result();
                    
                    //若调宿日期为空则计算日期为入住日期，若不为空则计算日期为调宿日期
                    if($query_people->tune_inDate == '')
                    {
                        $calcDate = $query_people->liveDate;
                    }
                    else
                    {
                        $calcDate = $query_people->tune_inDate;
                    }

                    //若计算日期的月份和当前月份一致，则计算计算日期与调宿日期之间的天数，若不一致则计算调宿日期与本月第一天之间的天数
                    if(substr($calcDate, 5, 2) == date("m"))
                    {
                        $datetime_start = new DateTime($calcDate);
                        $datetime_end = new DateTime($CoordinatingDate);
                        $days = $datetime_start->diff($datetime_end)->days;
                    }
                    else
                    {
                        $datetime_start = new DateTime(date("Y-m-01"));
                        $datetime_end = new DateTime($CoordinatingDate);
                        $days = $datetime_start->diff($datetime_end)->days;
                    }
                    
                    //判断此人员是否在dorm_days表中是否存在，若存在则证明此人进行过调宿
                    $data_days = $this->db->get_where('dorm_days', array('idNumber' => $idNumber, 'jobNumber' => $jobNumber ,'days' => '0', 'flag' => '1'));
                    $query_days = $data_days->result();

                    if($query_days)
                    {
                        //原宿舍数据
                        $arrDays = array(
                            'area_number' => explode(',', $check_inAddress)[0],
                            'floor_number' => explode(',', $check_inAddress)[1],
                            'dorm_floor' => explode(',', $check_inAddress)[2],
                            'room_number' => explode(',', $check_inAddress)[3],
                            'idNumber' => $idNumber,
                            'jobNumber' => $jobNumber,
                            'name' => $name,
                            'sex' => $sex,
                            'year' => date("Y"),
                            'month' => date("m"),
                            'days' => $days,
                            'flag' => '1'
                        );
                        //更新旧房间信息
                        $this->db->update('dorm_days', $arrDays);
                        $result_days1 = $this->db->affected_rows();

                        //新宿舍数据
                        $arrDays1 = array(
                            'area_number' => $area_number,
                            'floor_number' => $floor_number,
                            'dorm_floor' => $dorm_floor,
                            'room_number' => $room_number,
                            'idNumber' => $idNumber,
                            'jobNumber' => $jobNumber,
                            'name' => $name,
                            'sex' => $sex,
                            'year' => date("Y"),
                            'month' => date("m"),
                            'days' => '0',
                            'flag' => '1'
                        );
                        //插入新房间数据
                        $this->db->insert('dorm_days', $arrDays1);
                        $result_days2 = $this->db->affected_rows();
                        $result_days = $result_days1 && $result_days1;
                    }
                    else
                    {
                        $arrDays = array(
                            //原宿舍数据
                            array(
                                'area_number' => explode(',', $check_inAddress)[0],
                                'floor_number' => explode(',', $check_inAddress)[1],
                                'dorm_floor' => explode(',', $check_inAddress)[2],
                                'room_number' => explode(',', $check_inAddress)[3],
                                'idNumber' => $idNumber,
                                'jobNumber' => $jobNumber,
                                'name' => $name,
                                'sex' => $sex,
                                'year' => date("Y"),
                                'month' => date("m"),
                                'days' => $days,
                                'flag' => '1'
                            ),
                            //新宿舍数据
                            array(
                                'area_number' => $area_number,
                                'floor_number' => $floor_number,
                                'dorm_floor' => $dorm_floor,
                                'room_number' => $room_number,
                                'idNumber' => $idNumber,
                                'jobNumber' => $jobNumber,
                                'name' => $name,
                                'sex' => $sex,
                                'year' => date("Y"),
                                'month' => date("m"),
                                'days' => '0',
                                'flag' => '1'
                            )
                        );

                        //数据插入表
                        $this->db->insert_batch('dorm_days', $arrDays);
                        $result_days = $this->db->affected_rows();
                    }

                    $arr = array(
                        'area_number' => explode(',', $check_inAddress)[0],
                        'floor_number' => explode(',', $check_inAddress)[1],
                        'dorm_floor' => explode(',', $check_inAddress)[2],
                        'room_number' => explode(',', $check_inAddress)[3],
                        'date' => $CoordinatingDate
                    );

                    if($result_livepeople && $result_bed_old && $result_bed_new && $result_tune && $result_roominfor_old && $result_roominfor_new && $result_days)
                    {
                        // $return_su = array('res' => '40000', 'msg' => '宿舍调换成功', 'data' => $roomMeterArray);
                        $result = json_encode(array('res' => '40000', 'msg' => '宿舍调换成功', 'data' => $arr));
                        // $result = json_encode($return_su);
                    } 
                    else 
                    {
                        // $return_fa = array('res' => '40001', 'msg' => '宿舍调换失败', 'data' => '');
                        // $result = json_encode($return_fa);
                        $result = json_encode(array('res' => '40001', 'msg' => '宿舍调换失败', 'data' => ''));
                    }
                // }
            }
            return $result;
        }
    }
